package com.woniuxy.microfundservice.config;

import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/*
 * @author: masterhai
 * @date: 2021/4/8:10:02
 * @description:
 */

/**
 * @RibbonClients(defaultConfiguration = RibbonConfigure.class)
 * 定义当前类，就是Ribbon的默认配置类
 */
@RibbonClients(defaultConfiguration = RibbonConfigure.class)
@Configuration
public class RibbonConfigure {
    /**
     * blockHandler 限流的预处理方法 对应着GlobalExceptionHandler 类中limitRate()
     * blockHandlerClass 预处理方法 来自于哪个类
     * fallback 熔断的预处理方法
     * fallbackClass 预处理方法 来自于哪个类
     * @return
     */
    @Bean
    @SentinelRestTemplate(blockHandler="limitRate",blockHandlerClass = GlobeExceptionHandler.class,
            fallback = "fallback",fallbackClass = GlobeExceptionHandler.class)
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

}
